package loja.view.editor.components.combobox;

import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;

import loja.model.handler.PropertyView;
import loja.view.editor.components.ComponentEditor;

public class ComboBoxEditor<E> extends JComboBox<E> implements ComponentEditor,
		PropertyView {

	private static final long serialVersionUID = 1L;
	private String property;

	public ComboBoxEditor(String property) {
		super();
		this.property = property;
	}

	public ComboBoxEditor(E[] items, String property) {
		super(items);
		this.property = property;
	}

	public ComboBoxEditor(ComboBoxModel<E> aModel, String property) {
		super(aModel);
		this.property = property;
	}

	@Override
	public void onCancel() {
		setEnabled(false);

	}

	@Override
	public void onEdit() {
		setEnabled(true);
	}

	@Override
	public void onEnd() {

	}

	@Override
	public void onInclude() {
		setEnabled(true);
		setSelectedIndex(-1);
	}

	@Override
	public void onRemove() {
		setEnabled(false);
		setSelectedIndex(-1);

	}

	@Override
	public void onSave() {
		setEnabled(false);
	}

	@Override
	public void onStart() {
		setEnabled(false);
		setSelectedIndex(-1);

	}

	@Override
	public String getProperty() {
		return property;
	}

	@Override
	public Object getPropertyValue() {
		return getModel().getSelectedItem();
	}

	@Override
	public void setPropertyValue(Object value) {
		getModel().setSelectedItem(value);
	}

}
